/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('nbftestpop', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model ArrayOutputRequest {
  input?: {
    request?: string(name='request'),
    requestId?: string(name='requestId'),
  }(name='input'),
}

model ArrayOutputShrinkRequest {
  inputShrink?: string(name='input'),
}

model ArrayOutputResponse = {
  headers: map[string]string(name='headers'),
  body: [ string ](name='body'),
}

async function arrayOutput(request: ArrayOutputRequest): ArrayOutputResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return arrayOutputWithOptions(request, headers, runtime);
}

async function arrayOutputWithOptions(tmpReq: ArrayOutputRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ArrayOutputResponse {
  Util.validateModel(tmpReq);
  var request = new ArrayOutputShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.input)) {
    request.inputShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.input, 'input', 'json');
  }
  var query : map[string]any= {};
  if (!Util.isUnset(request.inputShrink)) {
    query.input = request.inputShrink;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  return doROARequest('ArrayOutput', '2021-08-04_14-46-22-100', 'HTTP', 'POST', 'AK', `/kxo/arrayoutput`, 'array', req, runtime);
}

